package com.smartcommunity.dao.village;

import com.smartcommunity.bean.entity.Build;
import com.smartcommunity.bean.entity.Village;
import com.smartcommunity.bean.entity.VillageEntranceExit;
import com.smartcommunity.entity.Unit.Unit;
import com.smartcommunity.entity.people.RealPeopleHouse;
import com.smartcommunity.entity.statistic.StatisticsVillageDataResp;
import com.smartcommunity.entity.village.Building;
import com.smartcommunity.entity.village.House;
import com.smartcommunity.entity.village.OrganizationVillage;
import com.smartcommunity.entity.village.SixStatisticsEntity;
import com.smartcommunity.entity.village.dto.VillageForPeopleManage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName: VillageDao
 * @Description: 小区相关（小区、楼栋、行政区划、水电煤、小区出入口、实有单位）DAO 
 * @author: minsheng
 * @Date: 2019/1/3 17:11
 * @Company:
 * @version V1.5.0
 */
@Mapper
public interface VillageDao {

    /*============================小区相关方法=====================================*/
    /**
     * @Description: 查询全部小区信息
     * @return: List<Village>
     * @author: minsheng
     * @date: 2019/1/3 14:27
     */
    List<Village> getAllVillageInfo();

    /**
     * 获取小区数量
     * @return
     */
    int getVillageCount();
    int getVillageCountByCode(Map map);

    /**
     * @Description: 查询所有楼栋数据
     * @param: Map<String, String>
     * @return: List<Building>
     * @author: minsheng
     * @date: 2019/1/3 14:26
     */
    List<Building> listBuildings(Building build);

    Building getBuildingById(@Param("id") String id);

    Building getBuilding(Building build);

    List<Build> listBuilds(Build build);
    /**
     * @Description: 查询楼栋的房屋数据
     * @param: Map<String, String>
     * @return: List<House>
     * @author: minsheng
     * @date: 2019/1/3 14:27
     */
    List<House> listHousesByBuilding(House house);
    
    List<House> listHousesByBuilding2(@Param("house")House house, @Param("start")Integer start, @Param("end")Integer end);
    
    int countHousesByBuilding(House house);

    /**
     * 查询房屋人员信息
     * @param map
     * @return
     */
    List<RealPeopleHouse> listPeopleByHouse(Map map);
    
    /**
     * @Description: 通过住户身份证查询房屋信息
     * @param: Map<String, String>
     * @return: List<Map<String,Object>>
     * @author: minsheng
     * @date: 2019/1/3 14:38
     */
    List<Map<String,Object>> listHouses(Map<String, String> map);

    /**
     * 通过小区编号查询小区信息
     * @param map
     * @return
     */
    List<Village> listVillagesByVillageCode(Map<String, Object> map);

    List<SixStatisticsEntity>  buildCountGroupByVillage();

    List<SixStatisticsEntity>  houseCountGroupByVillage();

    /**
     * 查询房屋编号
     * @param map
     * @return List<House>
     */
    List<House> listHouseNos(Map<String, String> map);

    /**
     * 查询楼栋编号
     * @param map
     * @return
     */
    List<House> listBuildingNos(Map<String, String> map);
    /**
     * 根据参数：parentId或小区编号获取小区列表
     * @param param 请求参数，包括小区父级组织机构标识parentId，数据权限小区编码集villageCodes
     * @return parentId
     */
    List<Village> getVillageListByParentId(Map<String, Object> param);
    /**
     * 获取小区基本信息ALL
     * @param param 请求参数，包括数据权限小区集
     * @return
     */
    List<Village> getAllVillage(Map<String, Object> param);

    /**
     * @Description: 新增小区
     * @author: minsheng
     * @date: 2019/1/3 16:41
     */
    void insertVillage(Village bean);
    /**
     * @Description: 更新小区
     * @param: bean
     * @return: void
     * @author: minsheng
     * @date: 2019/1/3 16:41
     */
    void updateVillage(Village bean);
    /**
     * @Description: 删除小区
     * @param: villageCode
     * @return: void
     * @author: minsheng
     * @date: 2019/1/3 16:42
     */
    void deleteVillage(@Param("villageCode") String villageCode);

    /**
     * @Description: 新增小区校验
     * @param: Map<String, Object>
     * @return: List<Map<String, Object>>
     * @author: minsheng
     * @date: 2019/1/3 16:42
     */
    List<Map<String, Object>> checkInsertVillage(Map<String, Object> map);
    /**
     * @Description: 更新小区校验
     * @param: Map<String, Object>
     * @return:  List<Map<String, Object>>
     * @author: minsheng
     * @date: 2019/1/3 16:58
     */
    List<Map<String, Object>> checkUpdateVillage(Map<String, Object> map);
    /**
     * @Description: 获取小区列表
     * @param: Map<String, Object>
     * @return: List<Village>
     * @author: minsheng
     * @date: 2019/1/3 16:32
     */
    List<Village> getVillageList(Map<String, Object> map);

    /**
     * 获取小区列表(大屏使用)
     * @param map
     * @return
     */
    List<StatisticsVillageDataResp> getStatisticsVillageList(Map<String, Object> map);

    /**
     * 实口管控获取小区列表,增加返回长期未出现人员数、未登记长期活动数、深夜出入数据
     * @param map
     * @return
     */
    List<VillageForPeopleManage> getVillageListForPeopleManage(Map<String, Object> map);
    /**
     * @Description: 获取小区实体
     * @param:  villageCode
     * @return: Village
     * @author: minsheng
     * @date: 2019/1/3 16:47
     */
    Village getVillage(@Param("villageCode") String villageCode);

    /**
     * @Description: 新增楼栋
     * @param:  List<Building>
     * @return: void
     * @author: minsheng
     * @date: 2019/1/3 16:53
     */
    void insertBuilding(List<Building> buildList);

    void addBuilding(Building build);

    int checkAddBuilding(Building build);

    int checkUpdateBuilding(Building build);

    /**
     * @Description: 更新楼栋
     * @param:  Building
     * @return: void
     * @author: minsheng
     * @date: 2019/1/3 16:53
     */
    void updateBuild(Building build);
    /**
     * @Description: 删除楼栋
     * @param:  id
     * @return: void
     * @author: minsheng
     * @date: 2019/1/3 16:53
     */
    void deleteBuild(@Param("id") String id);


    /*============================行政区划相关方法=====================================*/
    /**
     * 小区上层组织机构最高节点
     * @return
     */
    List<OrganizationVillage> OrganizationVillageOneID();
    /**
     * 根据ChildrenId获取小区上层组织机构LIST
     * @param id
     * @return
     */
    List<OrganizationVillage> listOrganizationVillageByChildrenId(Integer id);

    /**
     * 新增行政机构
     */
    void insertVillageOrg(OrganizationVillage bean);
    /**
     * 新增行政机构(批量)
     */
    void insertVillageOrgBatch(@Param("list") List<OrganizationVillage> list);
    /**
     * 更新行政机构
     */
    void updateVillageOrgByPrimaryKey(OrganizationVillage bean);
    /**
     * 删除行政机构
     */
    void deleteVillageOrgByPrimaryKey(Integer id);

    /**
     * @Description: 获取小区行政区划列表
     * @param: Map<String, Object>
     * @return: List<OrganizationVillage>
     * @author: minsheng
     * @date: 2019/1/3 16:31
     */
    List<OrganizationVillage> getVillageOrgList(Map<String, Object> map);

    /**
     * 校验行政区域名、orgCode是否重复
     */
    List<Map<String, Object>> checkVillageOrgNameRepeat(Map<String, Object> map);
    /**
     * 删除机构时校验是否挂有子机构、是否挂有小区
     */
    List<Map<String, Object>> checkOrgHaveVillage(Integer id);

    List<OrganizationVillage> getVillageOrgByOrgIds(@Param("ids")String ids);
    /**
     * 删除小区与机构关系
     * @param villageCode
     */
    void deleteVillageOrgByVillage(String villageCode);

    /**
     * 根据行政区划code查询主键ID
     */
    Integer getOrgIdByCode(String code);

    /**
     * 根据行政区划id 查询orgCode
     */
    String getOrgCodeById(String id);

    //查询所有的行政区划code
    List<String> getAllOrgCode();



    /*============================行政区划相关方法=====================================*/




    /*============================小区出入口相关方法=====================================*/

    List<VillageEntranceExit> listVillageEntranceExits(Map<String, String> map);
    /**
     * @Description: 通过小区编号查询小区出入口信息
     * @param:  Map<String, String>
     * @return: List<VillageEntranceExit>
     * @author: minsheng
     * @date: 2019/1/3 17:27
     */
    List<VillageEntranceExit> getVillageEntranceExitList(Map<String, Object> map);
    /**
     * 新增小区出入口
     * @param villageEntranceExit 出入口实体
     */
    void insertVillageEntranceExit(VillageEntranceExit villageEntranceExit);

    void insertVillageEntranceExits(List<VillageEntranceExit> list);
    /**
     * @Description: 编辑小区出入口
     * @param: VillageEntranceExit
     * @author: minsheng
     * @date: 2019/1/3 14:09
     */
    void updateVillageEntranceExit(VillageEntranceExit villageEntranceExit);
    /**
     * 删除小区出入口
     * @param id 主键id
     * @return
     */
    void deleteVillageEntranceExitById(@Param("id") String id);

    void deleteVillageEntranceExit(@Param("villageCode") String villageCode);

    /**
     * 删除小区楼栋信息
     * @param villageCode
     */
    void deleteVillageBuildingByCode(@Param("villageCode") String villageCode);


    /**
     * 校验小区出入口是否重名
     */
    Integer checkVillageEntranceExitNameRepeat(Map<String, Object> map);


    /**
     * @Description: 根据父ID获取小区列表
     * @param: parentId,villageName,villageCode
     * @return:  List<Village>
     * @author: minsheng
     * @date: 2019/1/14 16:40
     */
    List<Village> listVillageByParentId(Map<String, String> map);

    /**
     * @Description: 根据orgId获取小区信息
     * @param: map
     * @return: List<Village>
     * @author: minsheng
     * @date: 2019/1/16 18:32
     */
    List<Village> listVillagesByOrgId(Map<String, Object> map);


    /**
     * 根据小区code 获取其父级行政区划id
     * @param villageCode
     * @return
     */
    List<String> getParentIdsByVillageCode(@Param("villageCode") String villageCode);

    /**
     * 根据行政区划code获取 行政区划id
     * @param orgCode
     * @return
     */
    List<String> getOrgIdsByOrgCode(@Param("orgCode") String orgCode);

    String getVillageOrgByParentId(@Param("parentId") String parentId);

    String getAllChildOrgId(@Param("parentId") String parentId);
    
    /**
	 * 分页查询房屋(es-basedata索引数据初始化用)
	 * @return
	 */
	List<House> listHousesForEs(@Param("startRow")Integer startRow, @Param("endRow")Integer endRow);
	
	Integer getAllHouseCountForEs();

    /**
     * 根据小区编号和楼栋编号获取单元号
     * @param buildingNo 楼栋编号
     * @param villageCode 小区编号
     * @return
     */
	List<Unit> listUnitByBulidAndVillage(@Param("villageCode")String villageCode,@Param("buildingNo")String buildingNo);
	
	List<Map<String, Object>> getOrgNamesByVillageCodes(@Param("villageCodes") Set<String> villageCodes);
}